package com.example.dmdomain;

import com.example.dmdomain.entity.ChatSession;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface ChatSessionRepository extends JpaRepository<ChatSession, String>, JpaSpecificationExecutor<ChatSession> {
    @Query(value = "select * from chat_session where use_id= :userId and session_time >= :startDate and session_time < :endDate order by session_time desc", nativeQuery = true)
    List<ChatSession> findAllByDateAndUserId(@Param("userId") String userId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);

    @Query(value = "select * from chat_session where use_id= :userId and del_state = 3 order by session_time desc", nativeQuery = true)
    List<ChatSession> findAllByUserId(@Param("userId") String userId);

    @Query(value = "select * from chat_session where session_id= :sessionId", nativeQuery = true)
    List<ChatSession> findAllBySessionId(@Param("sessionId") String sessionId);
    @Query(value = "select * from chat_session where request_id= :requestId and del_state = 0", nativeQuery = true)
    List<ChatSession> findByRequestId(@Param("requestId") String requestId);

}
